<template>
    <div class="my-profile">
      <h2>我的信息</h2>
      
      <!-- 个人资料卡片 -->
      <el-card class="profile-card">
        <div slot="header" class="clearfix">
          <div class="title">个人资料</div>
          <el-button type="text" @click="editMode = !editMode">{{ editMode ? '保存' : '编辑' }}</el-button>
        </div>
        <el-form :model="user" label-width="80px" v-if="!editMode">
          <el-form-item label="用户名">
            <el-input v-model="user.username" disabled></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="user.email" disabled></el-input>
          </el-form-item>
        </el-form>
        <el-form :model="user" label-width="80px" v-else>
          <el-form-item label="用户名">
            <el-input v-model="user.username"></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="user.email"></el-input>
          </el-form-item>
        </el-form>
      </el-card>
      
      <!-- 订单信息卡片 -->
      <el-card class="order-card">
        <div slot="header" class="clearfix">
          <span class="title">订单信息</span>
        </div>
        <el-table :data="orders" v-if="orders.length > 0">
          <el-table-column prop="id" label="订单ID" width="100"></el-table-column>
          <el-table-column prop="productName" label="商品名称"></el-table-column>
          <el-table-column prop="quantity" label="数量" width="100"></el-table-column>
          <el-table-column prop="totalPrice" label="总价" width="120"></el-table-column>
        </el-table>
        <p v-else>暂无订单</p>
      </el-card>
      
      <!-- 已购买商品卡片 -->
      <el-card class="purchased-items-card">
        <div slot="header" class="clearfix">
          <span class="title">已购买商品</span>
        </div>
        <el-row :gutter="20" v-if="purchasedItems.length > 0">
          <el-col :span="6" v-for="item in purchasedItems" :key="item.id">
            <el-image :src="item.imageUrl" fit="cover"></el-image>
            <div class="item-details">
              <span class="item-name">{{ item.name }}</span>
              <span class="item-price">{{ '¥' + item.price }}</span>
            </div>
          </el-col>
        </el-row>
        <p v-else>暂无已购买商品</p>
      </el-card>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  import { ElCard, ElButton, ElForm, ElFormItem, ElInput, ElTable, ElTableColumn, ElImage, ElRow } from 'element-plus';
  
  const user = ref({
    username: 'example_user',
    email: 'example@example.com'
  });
  
  let editMode = ref(false);
  
  // 模拟订单数据
  const orders = ref([
    { id: 1, productName: '手机', quantity: 1, totalPrice: 1999 },
    { id: 2, productName: '电视', quantity: 1, totalPrice: 3999 },
  ]);
  
  // 模拟已购买商品数据
  const purchasedItems = ref([
    { id: 1, name: '手机', price: 1999, imageUrl: 'https://gw.alicdn.com/imgextra/i4/838801383/O1CN015LFsKq1M5SdR068rQ_!!838801383.jpg_Q75.jpg_.webp' },
    { id: 2, name: '电视', price: 3999, imageUrl: 'https://gw.alicdn.com/imgextra/i1/3378707715/O1CN01k4agFV26rW9x98sg6_!!3378707715.jpg_Q75.jpg_.webp' },
  ]);
  </script>
  
  <style scoped>
  .my-profile {
    padding: 20px;
  }
  .profile-card, .order-card, .purchased-items-card {
    margin-top: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  }
  .title {
    font-size: 18px;
    font-weight: bold;
  }
  .item-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
  }
  .item-name {
    font-size: 14px;
  }
  .item-price {
    font-size: 14px;
    color: #f56c6c;
  }
  </style>
  